package com.itany.corejava.code12_线程;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月29日 13:33
 */
public class Test08_线程安全问题 {
    public static void main(String[] args) {
        // TicketRunnale2 ticketRunnale2=new TicketRunnale2();
        // Thread t1=new Thread(ticketRunnale2);
        // Thread t2=new Thread(ticketRunnale2);
        // t1.start();
        // t2.start();
        // Ticket2 t1=new Ticket2();
        // Ticket2 t2=new Ticket2();
        // t1.start();
        // t2.start();

    }
}
class TicketRunnale2 implements Runnable{
    private int num=100;

    @Override
    public void run() {
        while(true){
            if(num==0){
                break;
            }else{
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"正在售票,当前第"+(num--));
            }
        }
    }
}

class Ticket2 extends Thread{
    private static  int num=10;
    @Override
    public void run() {
        while(true){
            if(num==0){
                break;
            }else{
                // try {
                //     Thread.sleep(10);
                // } catch (InterruptedException e) {
                //     e.printStackTrace();
                // }
                System.out.println(Thread.currentThread().getName()+"正在售票,当前第"+(num--));
            }
        }
    }
}
